package org.hackystat.ui.projectviewer.gwt.client.common;

import com.google.gwt.user.client.ui.Composite;

/**
 * Defines the model for all management panels.
 * 
 * @author Pavel Senin.
 * 
 */
public abstract class ManagementPanelWidget extends Composite {

  /**
   * Encapsulated information about a particular implementation. Each panel is expected to have a
   * static <code>init()</code> method that will be called by the wrapper on startup.
   * 
   * @author Pavel Senin.
   */
  public abstract static class Handler {
    private ManagementPanelWidget instance;
    private String name;

    /**
     * Sets the panel information.
     * 
     * @param name the panel name.
     */
    public Handler(String name) {
      this.name = name;
    }

    /**
     * Creates panel instance.
     * 
     * @return panel instance.
     */
    public abstract ManagementPanelWidget createInstance();

    /**
     * Reports panel instance, if instance not found creates one.
     * 
     * @return panel instance.
     */
    public final ManagementPanelWidget getInstance() {
      if (instance != null) {
        return instance;
      }
      return (instance = createInstance());
    }

    /**
     * Reports the panel widget name.
     * 
     * @return the panel widget name.
     */
    public String getName() {
      return this.name;
    }

    /**
     * Called just before this panel is hidden.
     */
    public void onHide() {
      assert true;
    }

    /**
     * Called just after this panel is shown.
     */
    public void onShow() {
      assert true;
    }
  }

}
